package logic

import (
	"context"
	"fmt"
	"srv/internal/svc"
	"srv/models/mysql"
	"srv/sesame"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *sesame.UserListRequest) (*sesame.UserListResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	list, err := u.GetUserList()
	if err != nil {
		return nil, err
	}
	var UserList []*sesame.UserInfo
	for _, user := range list {
		UserList = append(UserList, &sesame.UserInfo{
			Phone:    user.Phone,
			UserName: user.UserName,
			Status:   int64(user.Status),
			UseId:    int64(user.ID),
			Time:     user.Time,
		})
	}
	fmt.Println(mysql.User{})
	return &sesame.UserListResponse{
		List: UserList,
	}, nil
}
